// This source code is public domain.
// Written by Christopher E. Miller
// Scintilla Control example for DFL
// http://www.dprogramming.com/dfl.php
// http://wiki.dprogramming.com/Dfl/ScintillaControl

// To compile:
// 	dfl -gui dflscitest.d dflscintilla.lib
// Remember to have access to scilexer.dll from \lib

// For more information on using Scintilla, see http://www.scintilla.org/ScintillaDoc.html
// Scintilla.sendEditor() is used to send messages to a Scintilla control in DFL.


private import dfl.all;

private import dfl.scintilla; // DFL control.

class SciTestForm: dfl.form.Form {
	
static char[] KeyWords = 
		"asm auto  bool break "
		"case catch char class compl const const_cast continue "
		"default delete do double dynamic_cast else enum explicit export extern false float for "
		"friend goto if inline int long mutable namespace new not not_eq "
		"operator or or_eq private protected public "
		"register reinterpret_cast return short signed sizeof static static_cast struct switch "
		"template this throw true try typedef typeid typename union unsigned using "
		"virtual void volatile wchar dchar while xor module ";

static char[] text_1	= " module test ;
// com1
void main(){
	int foo	= 42 ;
	char[] t0	= \"string\" ;
	wchar[] t1	= r\"stringr\"  ;
	dchar[]t2	= `stringb` ;
}
";

	Scintilla sci;
	this() {
		startPosition = FormStartPosition.WINDOWS_DEFAULT_BOUNDS;
		text = "Scintilla Test Form";
		
		//with(sci = new Scintilla("dlex.dll"))
		with(sci = new Scintilla) {
			text		= text_1 ;
			dock		= DockStyle.FILL;
			parent	= this;
			
			handleCreated ~= &sci_handleCreated;
		}
	}
	
	void setAStyle(int style, int fore, int back = 0xffffff, int size = -1,  char[] face = null){
		with(sci){
			sendEditor(SCI_STYLESETFORE , style, fore );
			sendEditor(SCI_STYLESETBACK, style, back );
		}
		if (size >= 1){
			sci.sendEditor(SCI_STYLESETSIZE, style, size);
		}
		if (face){
			sci.sendEditor(SCI_STYLESETFONT, style, face);
		}
	}
	
	
	private void sci_handleCreated(Object sender, EventArgs ea) {
		with(sci){
			sendEditor(SCI_SETLEXER, SCLEX_D); // Set the lexer. CPP one is for C/C++/D/etc.
			
			sendEditor(SCI_STYLESETFONT, STYLE_DEFAULT, "Courier New"); // Default font name.
			sendEditor(SCI_STYLESETSIZE, STYLE_DEFAULT, 10 ); // Default font size.
			sendEditor(SCI_SETKEYWORDS, 0,  KeyWords ); // Set keywords.
			
			setAStyle(SCE_D_DEFAULT,  0 );
			setAStyle(SCE_D_COMMENT, 0x8000 );
			setAStyle(SCE_D_COMMENTLINE,  0x8000);
			setAStyle(SCE_D_COMMENTDOC, 0x8000 );
			setAStyle(SCE_D_COMMENTLINEDOC,  0x8000  );
			setAStyle(SCE_D_COMMENTDOCKEYWORD,  0x8000  );
			setAStyle(SCE_D_COMMENTDOCKEYWORDERROR, 0x8000 );
			setAStyle(SCE_D_NUMBER,  0x8080 );
			setAStyle(SCE_D_WORD,  0xf00000 );
			setAStyle(SCE_D_STRING, 0x880000);
			setAStyle(SCE_D_STRINGB, 0x8800);
			setAStyle(SCE_D_STRINGR, 0x88);
			
			sci.sendEditor(SCI_SETCODEPAGE, SC_CP_UTF8, 0);
		}
	}
}


int main(){
	try{
		Application.run(new SciTestForm());
	}catch(Object o){
		msgBox(o.toString(), "Fatal Error", MsgBoxButtons.OK, MsgBoxIcon.ERROR);
		return 1;
	}
	return 0;
}

